package com.icode.jersey.resource;

import com.icode.jersey.model.UserDTO;
import com.icode.jersey.service.UserService;
import com.icode.jersey.service.UserServiceImpl;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: alexz
 * Date: 14-7-11
 * Time: 上午10:53
 * To change this template use File | Settings | File Templates.
 */
@Path("user")
public class UserResource {
    private UserService userService = new UserServiceImpl();

    @POST
    @Produces(MediaType.APPLICATION_XML)
    @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
    public UserDTO createUser(@FormParam("username") String username, @FormParam("password") String password) {
        return userService.createUser(username, password);
    }

    @Path("{username}")
    @GET
    @Produces(value = MediaType.APPLICATION_XML)
    public UserDTO getUserDTO(@PathParam("username") String username) {
        return userService.loadUserDTOByUsername(username);
    }

    @GET
    @Produces(value = MediaType.APPLICATION_JSON)
    public List<UserDTO> getUserDTOs() {
        return userService.loadUserDTOs();
    }
}
